package com.example.demo.config;


import dev.langchain4j.community.model.dashscope.QwenChatModel;
import dev.langchain4j.community.model.dashscope.QwenEmbeddingModel;
import dev.langchain4j.community.model.dashscope.QwenStreamingChatModel;
import dev.langchain4j.model.chat.ChatLanguageModel;
import dev.langchain4j.model.chat.StreamingChatLanguageModel;
import dev.langchain4j.model.embedding.EmbeddingModel;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class LangChainConfig {
    @Value("${langchain4j.community.dashscope.embedding-model.api-key}")
    private String apiKey;

    @Value("${langchain4j.community.dashscope.embedding-model.model-name}")
    private String modelName;

    @Value("${langchain4j.community.dashscope.chat-model.api-key}")
    private String chatApiKey;

    @Value("${langchain4j.community.dashscope.chat-model.model-name}")
    private String chatModelName;


    /*
    配置chat模型
     */
    @Bean
    public ChatLanguageModel chatLanguageModel(){
        return QwenChatModel.builder()
                //.baseUrl("https://dashscope.aliyuncs.com/compatible-mode/v1")
                .apiKey(chatApiKey)
                .modelName(chatModelName)
                .build();
    }


    /**
     * 图像理解模型
     * @return
     */
    @Bean
    public ChatLanguageModel audioModel() {
        return QwenChatModel.builder()
                .baseUrl("https://dashscope.aliyuncs.com/api/v1") // 必须加这个
                .apiKey(chatApiKey)
                .modelName("qwen2.5-vl-72b-instruct") // 或者你用的具体 omni 版本
                .build();
    }



    /*
    配置向量化模型
     */
    @Bean
    public EmbeddingModel embeddingModel(){
        return QwenEmbeddingModel.builder()
                .baseUrl("https://dashscope.aliyuncs.com/api/v1")
                .apiKey(apiKey)
                .modelName(modelName)
                .build();
    }


    /*
    配置流式传输模型
     */
    @Bean
    public StreamingChatLanguageModel streamingChatLanguageModel(){
        return QwenStreamingChatModel.builder()
                .apiKey(chatApiKey)
                .modelName(chatModelName)
                .build();
    }
}
